#include "selectwindow.h"

SelectWindow::SelectWindow(QWidget *parent) : QMainWindow(parent)
{
    //设置固定尺寸
    this->setFixedSize(1000,600);

    //设置标题
    this->setWindowTitle("推箱子");

    //设置图标(QPixMap也可)
    this->setWindowIcon(QIcon(":/res/1.png"));

    //创建返回按钮
    GPushButton *backBtn = new GPushButton(":/res/BACK.png",":/res/backBtn.png");
    backBtn->setParent(this);
    backBtn->move(this->width()-backBtn->width(),this->height()-backBtn->height());
    connect(backBtn,&GPushButton::clicked,[=]{
        //延时发送信号
        QTimer::singleShot(200,this,[=]{
            //发送点击返回按钮的信号
            emit this->ChooseSceneBack();
        });
    });

    // 置空关卡
    this->Check = NULL;
    double position[4][2]={
        100,200,
        300,200,
        500,200,
        700,200
    };//位置列表

    //创建选关按钮
    for(int i=0;i<4;i++)
    {
        GPushButton *levelBtn = new GPushButton(QString(":/res/p%1.png").arg(i+1));
        levelBtn->setParent(this);
        levelBtn->move(position[i][0],position[i][1]);

        connect(levelBtn,&GPushButton::clicked,[=]{
            //实例化当前关卡
            Check = new Checkpoint(i+1);
            Check -> show();
            this->hide();

            //监听游戏场景中的返回信号
            connect(this->Check,&Checkpoint::ChooseSceneBack,[=]{
                this->show();//返回选关场景
                this->Check->close();//隐藏游戏场景
                delete this->Check;//删除动态变量
                this->Check = NULL;//置空
            });
        });
    }
}

void SelectWindow::paintEvent(QPaintEvent *)
{
    QPainter painter(this);
    QPixmap pix;
    pix.load(":/res/4.jpg");
    pix=pix.scaled(pix.width(),pix.height());
    painter.drawPixmap(0,0,1000,600,pix);
    //pix.load(":/res/image/Title.png");加载标题
    //painter.drawPixmap(this->width()*0.5-pix.width()*0.5,30,pix);
}
